package com.example.yuejian.yuejian.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.base.BaseActivity;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.CommiteQuestion;
import com.example.yuejian.yuejian.bean.UsersInfo;
import com.example.yuejian.yuejian.model.MastersModel;
import com.example.yuejian.yuejian.model.UserModel;

public class AskQusetionActivity extends BaseActivity {
private EditText et_content;
    private Button btn_ok;
    String mid;
    String username;
    private ModleListener<CommiteQuestion>listener=new ModleListener<CommiteQuestion>() {
        @Override
        public void onResponse(CommiteQuestion o) {
            CommiteQuestion res=o;
            if (0==res.getRetCode())
            {
                Toast.makeText(getApplication(),res.getRetMsg(),Toast.LENGTH_SHORT).show();
            }
            else {
                Toast.makeText(getApplication(),res.getRetMsg(),Toast.LENGTH_SHORT).show();
                finish();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getApplication(),"未知错误",Toast.LENGTH_SHORT).show();
        }
    };
    private ModleListener<UsersInfo> userinfoListener=new ModleListener<UsersInfo>() {
        @Override
        public void onResponse(UsersInfo o) {
            UsersInfo res=o;

            username=res.getNickname();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getApplication(),msg,Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ask_qusetion);
        initViews();
        initEvents();
        getData();
    }
    private void initViews()
    {
        et_content=(EditText)findViewById(R.id.et_ask_question);
        btn_ok=(Button)findViewById(R.id.btn_ask_ok);
    }
    private void initEvents()
    {
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
             doCommite();
            }
        });
    }
    private void getData()
    {
        Intent intent=getIntent();
       mid= intent.getStringExtra("mid");
        UserModel userModel=new UserModel();
        userModel.userInfo(getUser_id(),userinfoListener);

    }
    private  void doCommite()
    {    String name=username;
        MastersModel mastersModel=new MastersModel();
        mastersModel.AskMaster(getUser_id(),et_content.getText().toString(),mid,name,listener);
    }
}
